package com.jic.market.impl.rest.realtimeprice.realTimePriceHandler;

import com.google.common.collect.Maps;
import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.Map;

/**
 * description: BaseRealTimePriceHandlerFactory
 * date: 2020/4/8 16:42
 * author: wangys
 * version: 1.0
 */
@Component
public class BaseRealTimePriceHandlerFactory implements InitializingBean, ApplicationContextAware {
    @Setter
    private ApplicationContext applicationContext;

    private Map<Integer, BaseRealTimePriceHandler> handlerHashMap = Maps.newHashMap();


    @Override
    public void afterPropertiesSet() throws Exception {
        applicationContext.getBeansOfType(BaseRealTimePriceHandler.class)
                .forEach((k, v) -> {
                    handlerHashMap.put(v.handlerFrontType(), v);
                });
    }

    public BaseRealTimePriceHandler getBaseInfoHandler(Integer handlerFrontType) {
        return handlerHashMap.get(handlerFrontType);
    }
}
